/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.wii.elpro.web.action;

import com.wii.elpro.entity.SpdcfItem;
import com.wii.elpro.entity.User;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

/**
 *
 * @author User
 */
public class SpdcfFinanceEditItemAction extends org.apache.struts.action.Action {
    
    /* forward name="success" path="" */
    private final static String SUCCESS = "success";
    
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    public ActionForward execute(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            {
           HttpSession sess = request.getSession(true);
        User user = (User)sess.getAttribute("userSession");       
        if(user==null){
            return mapping.findForward("gagalLogin");            
        } 
        String id = request.getParameter("id");
        List list = new ArrayList();
        try{
            if(sess.getAttribute("listSpdcfItem")!=null){
                list = (List)sess.getAttribute("listSpdcfItem");
            }
            for(int x=0;x<list.size();x++){
                SpdcfItem si = (SpdcfItem)list.get(x);
                if(si.getProduk().getId()==Long.parseLong(id)){
                    sess.setAttribute("item", si);                    
                    break;
                }
            }            
        }catch(Exception e){
            e.printStackTrace();
        }
        return mapping.findForward(SUCCESS);
        
    }
}